/**
 * @file TcpConnection.hh
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-07
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "InetAddress.hh"
#include "Socket.hh"
#include "SocketIO.hh"

namespace snow
{

class TcpConnection
{
public:
    TcpConnection(int fd);
    ~TcpConnection();

    string recv();
    string recvLine();
    void send(const string &msg);

    void shutdown(); // 关闭写端

    string printTcp() const; // 打印TCP连接，四元组（本端ip,port,对端ip,port)
    InetAddress getLocalAddress() const;
    InetAddress getPeerAddress() const;

private:
    Socket sock_;
    InetAddress localAddr_;
    InetAddress peerAddr_;
    SocketIO sockio_;
    bool isShutdownWrite_; // 是否关闭本端的写端
};

} // namespace snow